home *** CD-ROM | disk | FTP | other *** search
- /* ANOVA - Two Way */
-
- options results
- if ~show('P','TCALC') then do
- address command 'run turbocalc:turbocalc'
- address command 'waitforport TCALC'
- loadflag=1
- end
- address 'TCALC'
- 'DEFPUBSCREEN()'
- /* Add-in Rexx Math Library needed for some routines */
- signal on syntax
- if ~show('l','rexxmathlib.library') then
- call addlib('rexxmathlib.library',0,-30)
- if ~show('l','rexxreqtools.library') then
- call addlib('rexxreqtools.library',0,-30)
- if ~show('l','rexxsupport.library') then
- call addlib('rexxsupport.library',0,-30)
- /* add to library list */
- signal off syntax
-
- /* Start Main Routine */
- if loadflag=1 then 'Load()'
- 'ActivateWindow()'
- range=rtgetstring(,"Enter Cell Range for Input","Input Request") /*,,'rt_pubscrname="TCALC"')*/
- colon=pos(":",range)
- if colon=0 then do
- 'Message "Please select a range before executing this script"'
- 'DEFPUBSCREEN("Workbench")'
- exit
- end
-
- /* Find cell references and cell, column numbers */
- start_cell=substr(range,1,colon-1)
- end_cell=substr(range,colon+1)
- start_row=cellrow(start_cell)
- end_row=cellrow(end_cell)
- start_col=cellcol(start_cell)
- end_col=cellcol(end_cell)
- NRows=end_row-start_row+1
- NCols=end_col-start_col+1
-
- /* Get Number of Rows per Sample */
- rows=0
- rows=rtgetlong(,"Enter Number of Rows in each sample","Get Rows") /*,,'rt_pubscrname="TCALC"')*/
- if rows=0 then exit
- if datatype(left(rows,1),'n')=0 then do
- 'Message "Invalid row number"'
- 'DEFPUBSCREEN("Workbench")'
- exit
- end
-
- /* Get cell reference for output range */
- out_cell=rtgetstring(,"Enter Cell Reference for Output","Input Request") /*,,'rt_pubscrname="TCALC"')*/
- if out_cell="" then do
- 'DEFPUBSCREEN("Workbench")'
- exit
- end
- if length(out_cell)<2 | datatype(left(out_cell,1),'n')=1 then do
- 'Message "Invalid cell reference"'
- 'DEFPUBSCREEN("Workbench")'
- exit
- end
- /* Suppress Screen Redraw to Speed Things Up */
- 'Refresh 0'
-
- /* Open a small output window on tcalc screen*/
- fo=0
- CR='0a'x
- DisplayMsg="Calculating...Please Wait."||CR||"User input is disabled during calculation."||CR
- if open(6Info, 'con:100/0/450/80/Progress/SCREEN TCALC', w) then do
- call writeln(6Info, DisplayMsg)
- fo=1
- end
- else do
- 'Message "TCALC Screen not available for Progress messages"'
- end
- CALL DELAY(150)
-
- /* Get cell references for top cell in each column */
- 'SelectCell' start_cell
- do col=start_col to end_col
- 'GetCursorPos'
- top_cell.col=result
- 'Column 1'
- end
- /* Get labels for later use on output */
- 'SelectCell' start_cell
- 'Column 1'
- 'GetValue'
- testlabel=result
- testlabel=strip(testlabel)
- if datatype(testlabel,'n')=1 then do
- labelflag=0
- do x=start_col+1 to end_col
- title.x="Column "||x
- end
- end
- else do
- labelflag=1
- NRows=NRows-1
- do x=start_col+1 to end_col
- 'GetValue'
- str=result
- title.x=translate(strip(str),"_"," ")
- 'Column 1'
- end
- end
- 'SelectCell' start_cell
- w=0
- NR=NRows
- if labelflag=1 then NRows=Nrows+1
- do x=1 to NRows
- 'GetValue'
- testlabel=result
- testlabel=strip(testlabel)
- if datatype(testlabel,'a')=1 then do
- w=w+1
- 'GetValue'
- sampletitle.w=result
- say sampletitle.w
- end
- 'CursorDown 1'
- end
- NRows=NR
- NumSamples=w /* Number of samples */
- if fo then call writech(6Info,"Progress...10 ")
-
- /* Get data from cell range */
- col=start_col
- s=0
- z=0
- lav=0
- tot=0
- data.=0
- count.=0
- total.=0
- cell.=0
- do x=2 to NCols
- s=1
- col=col+1
- 'SelectCell' top_cell.col
- if labelflag=1 then 'CursorDown 1'
- do y=1 to NRows
- z=z+1
- 'GetValue'
- valtest=result
- if datatype(valtest)='NUM' then do
- 'GetValue'
- val=result
- data.s.x.y=val
- tot=tot+val
- total.x=tot
- count.x=1+count.x
- cell.s.x=(cell.s.x)+val
- end
- 'CursorDown 1'
- if z=rows then do
- z=0
- s=s+1
- end
- end
- tot=0
- lav=0
- val=0
- end
- rowtot.=0
- do s=1 to NumSamples
- do x=2 to NCols
- rowtot.s=(cell.s.x)+rowtot.s
- end
- end
- scount=rows*(NCols-1)
- if fo then call writech(6Info,"20 ")
-
- /* Calculate Means */
- meancol.=0
- meanrow.=0
- meanrc.=0 /* Means within cells of sample */
- GM=0 /* Grand Mean of all observations */
- NumObs=0 /* Total number of observations */
- GT=0 /* Grand Total of all observations */
- do x=2 to NCols
- meancol.x=total.x/count.x
- NumObs=NumObs+count.x
- GT=GT+total.x
- end
- do s=1 to NumSamples
- meanrow.s=(rowtot.s)/scount
- end
- GM=GT/NumObs
- do s=1 to NumSamples
- do x=2 to NCols
- meanrc.s.x=(cell.s.x)/rows
- end
- end
- if fo then call writech(6Info,"30 ")
-
- /* Calculate Standard deviation and Variance */
- dat=0
- meenx=0
- sum.=0
- sd.=0
- var.=0
- z=0
- N=rows-1
- do x=2 to NCols
- s=1
- do y =1 to NRows
- meen=meanrc.s.x
- z=z+1
- dat=data.s.x.y
- sum.s.x=(dat-meen)**2+(sum.s.x)
- if z=rows then do
- var.s.x=(sum.s.x)/N /* Variance & SD within cells */
- sd.s.x=sqrt(var.s.x)
- z=0
- s=s+1
- end
- end
- end
- summ.=0
- varrow.=0
- sdrow.=0
- s=1
- z=0
- N=((Ncols-1)*rows)-1
- do y=1 to NRows
- z=z+1
- do x=2 to NCols
- meen=meanrow.s
- dat=data.s.x.y
- summ.s=(dat-meen)**2+(summ.s)
- end
- if z=rows then do
- varrow.s=(summ.s)/N /* Variance & SD of sample */
- sdrow.s=sqrt(varrow.s)
- z=0
- s=s+1
- end
- end
- if fo then call writech(6Info,"40 ")
- summcol.=0
- varcol.=0
- sdcol.=0
- z=0
- N=NRows-1
- do x=2 to NCols
- s=1
- meen=meancol.x
- do y=1 to NRows
- z=z+1
- dat=data.s.x.y
- summcol.x=(dat-meen)**2+(summcol.x)
- if z=rows then do
- z=0
- s=s+1
- end
- end
- varcol.x=(summcol.x)/N /* Variance & SD of columns */
- sdcol.x=sqrt(varcol.x)
- end
- /* Calculate Sum of Squares */
- SSR=0 /* Sum of Squares Rows */
- SSC=0 /* Sum of Squares Columns */
- SSW=0 /* Sum of Squares Within Cells */
- SSTotal=0 /* Sum of Squares Total */
- SSI=0 /* Sum of Squares Interaction */
-
- /* Calculate SSR */
- ss=0
- do s=1 to NumSamples
- ss=ss+((meanrow.s)-GM)**2
- end
- SSR=ss*(NCols-1)*rows
- /* Calculate SSC */
- ss=0
- do x=2 to NCols
- ss=ss+((meancol.x)-GM)**2
- end
- SSC=ss*NumSamples*rows
- if fo then call writech(6Info,"50 ")
- /* Calculate SSI */
- ss=0
- do s=1 to NumSamples
- do x=2 to NCols
- ss=ss+((meanrc.s.x)-(meanrow.s)-(meancol.x)+GM)**2
- end
- end
- SSI=ss*rows
-
- /* Calculate SSW */
- ss=0
- z=0
- do x=2 to NCols
- s=1
- do y=1 to NRows
- z=z+1
- ss=ss+((data.s.x.y)-(meanrc.s.x))**2
- if z=rows then do
- z=0
- s=s+1
- end
- end
- end
- SSW=ss
- if fo then call writech(6Info,"60 ")
- /* Calculate SSTotal */
- ss=0
- z=0
- do x=2 to NCols
- s=1
- do y=1 to NRows
- z=z+1
- ss=ss+((data.s.x.y)-GM)**2
- if z=rows then do
- z=0
- s=s+1
- end
- end
- end
- SSTotal=ss
- /* Calculate Variances */
- DFR=NumSamples-1 /* Degrees of Freedom Rows */
- DFC=NCols-2 /* Degrees of Freedom Columns */
- DFI=DFR*DFC /* Degress of Freedom Interaction */
- DFW=NumSamples*(NCols-1)*(Rows-1) /* Degrees of Freedom Within Cells */
- DFT=rows*NumSamples*(NCols-1)-1 /* Degrees of Freedom Total */
- VarR=SSR/DFR /* Variance Estimate for Samples */
- VarC=SSC/DFC /* Variance Estimate for Columns */
- VarW=SSW/DFW /* Variance estimate for Within Cells */
- VarI=SSI/DFI /* Variance Estimate for Interaction */
- Fcol=VarC/VarW /* F Ratio for Columns */
- Frow=VarR/VarW /* F Ratio for Rows */
- Finter=VarI/VarW /* F Ratio for Interaction */
- if fo then call writech(6Info,"70 ")
-
- /* Calculate Probabilities */
-
- AC=.0001
- EC=.005
- EC2=EC+EC
- PCol=PROBABILITY(Fcol,DFC,DFW)
- PCol=1-PCol
- PRow=PROBABILITY(Frow,DFR,DFW)
- PRow=1-PRow
- PInt=PROBABILITY(Finter,DFI,DFW)
- PInt=1-PInt
- /* P=.95 OR .99 */
- FCRIT1Col=FCRITICAL(.95,DFC,DFW)
- FCRIT2Col=FCRITICAL(.99,DFC,DFW)
- if fo then call writech(6Info,"80 ")
- /* P=.95 OR .99 */
- FCRIT1Row=FCRITICAL(.95,DFR,DFW)
- FCRIT2Row=FCRITICAL(.99,DFR,DFW)
- /* P=.95 OR .99 */
- if fo then call writech(6Info,"90 ")
- FCRIT1Int=FCRITICAL(.95,DFI,DFW)
- FCRIT2Int=FCRITICAL(.99,DFI,DFW)
- if fo then do
- call writeln(6Info,"100 ")
- call writeln(6Info,"Writing output to window...")
- end
- /* Output */
- 'SelectCell' out_cell
- 'ColumnWidth 10'
- 'Put "ANOVA - Two Way: With Replication"'
- 'CursorDown 2'
- 'Put "Summary Statistics"'
- 'CursorDown 2'
- 'GetCursorPos'
- go_cell=result
- do x=start_col+1 to end_col
- 'ColumnWidth 10'
- 'Column 1'
- 'Alignment 2'
- title=""""||title.x||""""
- 'Put' title
- end
- 'Column 1'
- 'ColumnWidth 10'
- 'Alignment 2'
- 'Put' "Total"
- 'SelectCell' go_cell
- 'CursorDown 2'
- do s=1 to NumSamples
- 'GetCursorPos'
- start_cell=result
- sampletitle=""""||sampletitle.s||""""
- 'Put' sampletitle
- 'CursorDown 1'
- 'Put' "Count:"
- 'CursorDown 1'
- 'Put' "Sum:"
- 'CursorDown 1'
- 'Put' "Mean:"
- 'CursorDown 1'
- 'Put' "Variance:"
- 'CursorDown 1'
- 'GetCursorPos'
- end_cell=result
- 'SelectCell' start_cell
- 'CursorDown 1'
- do x=2 to NCols
- 'Column 1'
- 'Put' rows
- 'CursorDown 1'
- 'Put' cell.s.x
- 'CursorDown 1'
- 'Put' format(meanrc.s.x,,4)
- 'CursorDown 1'
- 'Put' format(var.s.x,,4)
- 'CursorUp 3'
- end
- 'Column 1'
- 'Put' scount
- 'CursorDown 1'
- 'Put' rowtot.s
- 'CursorDown 1'
- 'Put' format(meanrow.s,,4)
- 'CursorDown 1'
- 'Put' format(varrow.s,,4)
- 'CursorDown 1'
- 'SelectCell' end_cell
- 'CursorDown 2'
- end
- 'Put "Col. Total"'
- 'CursorDown 2'
- 'GetCursorPos'
- start_cell=result
- 'Put' "Count"
- 'CursorDown 1'
- 'Put' "Sum:"
- 'CursorDown 1'
- 'Put' "Mean:"
- 'CursorDown 1'
- 'Put' "Variance:"
- 'GetCursorPos'
- end_cell=result
- 'SelectCell' start_cell
- do x=2 to NCols
- 'Column 1'
- 'Put' count.x
- 'CursorDown 1'
- 'Put' total.x
- 'CursorDown 1'
- 'Put' format(meancol.x,,4)
- 'CursorDown 1'
- 'Put' format(varcol.x,,4)
- 'CursorUp 3'
- end
- 'SelectCell' end_cell
- 'CursorDown 2'
- 'Put' "ANOVA"
- 'CursorDown 2'
- 'GetCursorPos'
- start_cell=result
- 'Alignment 2'
- 'Put "Source of"'
- 'CursorDown 1'
- 'Alignment 2'
- 'Put "Variation"'
- 'Column 1'
- 'CursorUp 1'
- 'Alignment 2'
- 'Put "Sum of"'
- 'CursorDown 1'
- 'Alignment 2'
- 'Put "Squares"'
- 'Column 1'
- 'CursorUp 1'
- 'Alignment 2'
- 'Put "Degrees of"'
- 'CursorDown 1'
- 'Alignment 2'
- 'Put "Freedom"'
- 'Column 1'
- 'CursorUp 1'
- 'Alignment 2'
- 'Put' "Variance"
- 'CursorDown 1'
- 'Alignment 2'
- 'Put "Estimate"'
- 'Column 1'
- 'CursorUp 1'
- 'Alignment 2'
- 'Put "F Ratio:"'
- 'SelectCell' Start_cell
- 'CursorDown 2'
- 'Put' "Sample:"
- 'CursorDown 1'
- 'Put' "Column:"
- 'CursorDown 1'
- 'Put' "Interaction:"
- 'CursorDown 1'
- 'Put "Within Cells:"'
- 'CursorDown 1'
- 'Put' "Total:"
- 'CursorDown 2'
- 'GetCursorPos'
- test_cell=result
- 'SelectCell' Start_cell
- 'CursorDown 2'
- 'Column 1'
- 'Put' format(SSR,,4)
- 'CursorDown 1'
- 'Put' format(SSC,,4)
- 'CursorDown 1'
- 'Put' format(SSI,,4)
- 'CursorDown 1'
- 'Put' format(SSW,,4)
- 'CursorDown 1'
- 'Put' format(SSTotal,,4)
- 'CursorUp 4'
- 'Column 1'
- 'Put' DFR
- 'CursorDown 1'
- 'Put' DFC
- 'CursorDown 1'
- 'Put' DFI
- 'CursorDown 1'
- 'Put' DFW
- 'CursorDown 1'
- 'Put' DFT
- 'CursorUp 4'
- 'Column 1'
- 'Put' format(VarR,,4)
- 'CursorDown 1'
- 'Put' format(VarC,,4)
- 'CursorDown 1'
- 'Put' format(VarI,,4)
- 'CursorDown 1'
- 'Put' format(VarW,,4)
- 'CursorUp 3'
- 'Column 1'
- 'Put' format(Frow,,4)
- 'CursorDown 1'
- 'Put' format(Fcol,,4)
- 'CursorDown 1'
- 'Put' format(Finter,,4)
- 'SelectCell' test_cell
- 'Put "P(F Sample <=f):"'
- 'CursorDown 1'
- 'Put "F-Critical One-Tail(95%):"'
- 'CursorDown 1'
- 'Put "F-Critical One-Tail(99%):"'
- 'CursorDown 1'
- 'Put "P(F Column <=f):"'
- 'CursorDown 1'
- 'Put "F-Critical One-Tail(95%):"'
- 'CursorDown 1'
- 'Put "F-Critical One-Tail(99%):"'
- 'CursorDown 1'
- 'Put "P(F Interaction <=f):"'
- 'CursorDown 1'
- 'Put "F-Critical One-Tail(95%):"'
- 'CursorDown 1'
- 'Put "F-Critical One-Tail(99%):"'
- 'SelectCell' test_cell
- 'Column 2'
- 'Put' format(PRow,,6)
- 'CursorDown 1'
- 'Put' format(FCRIT1Row,,4)
- 'CursorDown 1'
- 'Put' format(FCRIT2Row,,4)
- 'CursorDown 1'
- 'Put' format(PCol,,6)
- 'CursorDown 1'
- 'Put' format(FCRIT1Col,,4)
- 'CursorDown 1'
- 'Put' format(FCRIT2Col,,4)
- 'CursorDown 1'
- 'Put' format(PInt,,6)
- 'CursorDown 1'
- 'Put' format(FCRIT1Int,,4)
- 'CursorDown 1'
- 'Put' format(FCRIT2Int,,4)
- 'Refresh 1'
- 'Refresh 2'
- /*'Message' "Finished"*/
- /*indicate the main script is finished*/
- DisplayMsg="Cleaning up ...."||CR||"Exiting"
- result=writeln(6Info, DisplayMsg)
- if result~=0 then do
- /*Wait 3 seconds*/
- CALL DELAY(150)
- /* close window*/
- result=close(6Info)
- end
- 'DEFPUBSCREEN("Workbench")'
- exit
-
- /* Procedures */
-
- cellrow: procedure
- do
- parse arg cell
- do charpos=2 to length(cell)
- if datatype(substr(cell,charpos,1),n) then return substr(cell,charpos)
- end
- return 0
- end
- Return
-
- cellcol: procedure
- do
- parse arg cell
- labels="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- cell=upper(cell)
- len=length(cell)
- val=0
- do charpos=1 to len
- if datatype(substr(cell,charpos,1),n) then
- do cell=reverse(substr(cell,1,charpos-1))
- do x=1 to length(cell)
- val=(26**(x-1))*pos(substr(cell,x,1),labels)+val
- end
- return val
- end
- end
- return 0
- end
- Return
-
- syntax:
- if arg(1)='FAIL' then do
- 'Message' "Library is unavailable."
- 'DEFPUBSCREEN("Workbench")'
- exit
- end
- 'Message' "Unknown Syntax Error"
- 'DEFPUBSCREEN("Workbench")'
- exit
-
- Format: procedure
-
- arg number, before, after
- CallLine = SIGL
- if ~datatype(CallLine, 'N') then CallLine = '??'
-
- /* Make sure we have a number as first (required) argument */
- if ~datatype(number, 'N') then do
- if number = '' then
- fc = 17 /* Wrong number of arguments */
- else
- fc = 47 /* Arithmetic conversion error */
- signal FormatSyntaxError
- end
- num = number + 0
- if before = '' & after = '' then
- return num
- else do
- parse var num integer '.' fraction
- if before = '' then before = length(integer)
- if after = '' then after = length(fraction)
- if ~datatype(before, N) | ~datatype(after, N) then
- do fc = 18
- signal FormatSyntaxError
- end
- if before < length(integer) then do
- fc = 18
- signal FormatSyntaxError
- end
- if after ~= length(fraction) then do
- fraction = trunc(('.'fraction'0') + ('.'copies('0', after)'5'), after)
- if integer<1&integer>-1 then integer=integer
- else integer = integer + (fraction % 1)
- fraction = substr(fraction, 3)
- end
- if fraction >= 0 then
- return right(integer, before)'.'fraction
- else
- return right(integer, before)
- end
-
- FormatSyntaxError:
- if show('F', STDERR) then
- call writeln(STDERR, '+++ Error' fc 'in line' CallLine':' errortext(fc))
- else
- mess='+++ Error' fc 'in line' CallLine':' errortext(fc)
- 'Message' mess
- parse source Func .
- if Func = 'FUNCTION' then do
- 'DEFPUBSCREEN("Workbench")'
- exit "Err"
- end
- else do
- 'DEFPUBSCREEN("Workbench")'
- exit 10
- end
-
- FCRITICAL: PROCEDURE EXPOSE AC EC EC2
-
- PARSE ARG PO,K1,K2
- /* fIND NORMAL Z CORRESPONDING TO P */
- P1=PO
- Z=NORMALPP(PO)
- IF K2<3 THEN DO
- W=K2**.75
- W=Z/W
- Z=Z*(1.1581-W*(.2296+W*(.0042+.0027*W)))
- END
- /* FIND INITIAL APPROX. TO F */
- A1=2/(9*K1)
- A2=2/(9*K2)
- W=Z*Z
- W1=1+A2*(A2-W-2)
- W2=A1+A2-A1*A2-1
- W3=1+A1*(A1-W-2)
- SN=SIGN(W2*W2-W1*W3)
- IF SN=-1 THEN W3=-1*SQRT(ABS(W2*W2-W1*W3))
- ELSE W3=SQRT(W2*W2-W1*W3)
- FO=(W3-W2)/W1
- FO=FO**3
- /* MODIFIED NEWTON ITERATION TO IMPROVE VALUE OF F */
- DO FOREVER
- FCRIT=FO
- PO=PROBABILITY(FCRIT,K1,K2)
- F1=PO-P1
- FCRIT=FO+EC
- PO=PROBABILITY(FCRIT,K1,K2)
- F2=PO
- FCRIT=FO-EC
- PO=PROBABILITY(FCRIT,K1,K2)
- F2=F2-PO
- F2=F2/EC2
- F1=FO-F1/F2
- IF ABS(F1-FO)>AC THEN FO=F1
- ELSE LEAVE
- END
- FCRIT=F1
- RETURN FCRIT
-
- NORMALPP: PROCEDURE
-
- ARG P0
- A1=2.515517
- A2=.802853
- A3=.010328
- A4=1.432788
- A5=.189269
- A6=.001308
- Q=.5-ABS(P0-.5)
- SN=SIGN(-2*LN(Q))
- IF SN=-1 THEN W=-1*SQRT(ABS(-2*LN(Q))
- ELSE W=SQRT(-2*LN(Q))
- W1=A1+W*(A2+A3*W)
- W2=1+W*(A4+W*(A5+A6*W))
- ZZ=W-W1/W2
- SELECT
- WHEN (P0-.5)<0 THEN TT=-1
- WHEN (P0-.5)=0 THEN TT=0
- otherwise TT=1
- END
- ZZ=ZZ*TT
- RETURN ZZ
-
- PROBABILITY: PROCEDURE EXPOSE AC EC EC2
-
- PARSE ARG F,K1,K2
- IF K1=1 THEN AC=.00001
- H2=K2/2
- H1=K1/2
- H3=H1+H2
- L1=0
- XX=H1
- LG=LOGGAMMA(XX)
- L1=L1+LG
- XX=H2
- LG=LOGGAMMA(XX)
- L1=L1+LG
- XX=H3
- LG=LOGGAMMA(XX)
- L1=L1-LG
- W1=K2/(K2+K1*F)
- XX=0
- IF H2<(H3*W1) THEN DO
- W2=W1
- W1=1-W1
- W3=H2
- H2=H1
- H1=W3
- END
- ELSE DO
- W2=1-W1
- XX=1
- END
- T1=1
- W3=1
- P=1
- I=INT(H1+W2*H3)
- W4=W1/W2
- /*LABELB:*/
- T2=H1-W3
- IF I=0 THEN W4=W1
- /*LABELC:*/
- DO FOREVER
- T1=T1*T2*W4/(H2+W3)
- P=P+T1
- T2=ABS(T1)
- IF (T2<=AC) & (T2<=AC*P) THEN LEAVE /*SIGNAL 'LABELD'*/
- W3=W3+1
- I=I-1
- IF I>=0 THEN DO /*SIGNAL 'LABELB'*/
- T2=H1-W3
- IF I=0 THEN W4=W1
- ITERATE
- END
- T2=H3
- H3=H3+1
- /*SIGNAL 'LABELC'*/
- END
- /*LABELD:*/
- W1=EXP(H2*LN(W1)+(H1-1)*LN(W2)-L1)
- P=P*W1/H2
- IF XX=0 THEN PO=P
- ELSE PO=1-P
- AC=.001
- RETURN PO
-
- LOGGAMMA: PROCEDURE
-
- ARG XA
- C1=76.18009173
- C2=-86.50532033
- C3=24.01409822
- C4=-1.231739516
- C5=.001208580
- C6=-.000005364
- C7=2.506628275
- X1=XA-1
- W=X1+5.5
- W=(X1+.5)*LN(W)-W
- S=1+C1/(X1+1)+C2/(X1+2)+C3/(X1+3)
- S=S+C4/(X1+4)+C5/(X1+5)+C6/(X1+6)
- L=W+LN(C7*S)
- RETURN L